<template>
  <div>
    <div class="mui-card lunbo">
      <div class="mui-card-content">
        <van-swipe :autoplay="3000">
          <van-swipe-item v-for="(image, index) in images" :key="index">
            <img v-lazy="image">
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <transition
      @before-enter = "beforeEnter"
      @enter = "enter"
      @after-enter = "afterEnter"
    >
      <div class="ball" v-show="ballshow"></div>
    </transition>
    
    <div class="mui-card">
      <div class="mui-card-header">{{goodsInfo.title}}</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p class="price">
            市场价：
            <del>￥{{goodsInfo.market_price}}</del>&nbsp;&nbsp;销售价：
            <span class="now_price">￥{{goodsInfo.sell_price}}</span>
          </p>
          <p>购买数量</p> <span>库存:{{goodsInfo.stock_quantity}}</span>
          <van-stepper v-model="value" :max="goodsInfo.stock_quantity" />
          <p>
            <mt-button type="primary" size="small">立即购买</mt-button>
            <mt-button type="danger" size="small" @click="addToShopCar">加入购物车</mt-button>
          </p>
        </div>
      </div>
    </div>{{this.$store.state.car}}
    <comment :id="id"></comment>
  </div>
</template>
<script>
import comment from '@/commt/comment.vue'
import { goodsgetinfo, getthumimages } from "@/api"
export default {
  data() {
    return {
      id: this.$route.params.id,
      images: [],
      goodsInfo: {},
      value:'',
      ballshow: false
    };
  },
  methods: {
    addToShopCar() {
      this.ballshow = !this.ballshow
      let goodsinfo ={
        id:this.id,
        count: parseInt(this.value), 
        price:this.goodsInfo.sell_price,
        selected:true
      }
     this.$store.commit('add',goodsinfo)
    },
    getSelectedCount() {},
    beforeEnter(el){
      el.style.transform = "translate(0px,0px)"
    },
    enter(el,done){
      el.offsetWidth
      el.style.transform = "translate(100px,100px)"
      el.style.trasition = "all 2s"
      done()
    },
    afterEnter(el){
      this.ballshow = false
    }
  },
  created() {
    getthumimages(this.id).then(res => {
      this.images = res.data.message;
    });
    goodsgetinfo(this.id).then(res => {
      console.log(res)
      this.goodsInfo = res.data.message[0];
    });
    console.log(this.$store.state.car)
  },
  components:{
    comment
  }
};
</script>
<style lang="less" scoped>
.ball{
  position: absolute;
  left: 85px;
  top: 460px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background-color: red;
  z-index: 1000;
}
.lunbo {
  padding: 10px 20px;
  img {
    width: 100%;
    height: 210px;
  }
}
.mui-card {
  padding: 10px 20px;
  p {
    display:inline-block;
    padding: 10px;
    margin: 0;
  }
  /deep/input{
      width: 28px;
      height: 28px;
      padding: 0;
      margin: 0;
  }
}

</style>
